﻿using System;
using System.Collections;
using System.Collections.Generic;
using Entitas;
using UnityEngine;

public class ScoreSystem : ReactiveSystem<GameEntity>,IInitializeSystem
{
    
    private Contexts _contexts;
    public ScoreSystem(Contexts context) : base(context.game)
    {
        _contexts = context;
    }

    protected override ICollector<GameEntity> GetTrigger(IContext<GameEntity> context)
    {
        return context.CreateCollector(GameMatcher.ComponentsItem.Removed());
    }

    protected override bool Filter(GameEntity entity)
    {
        return !entity.isComponentsItem;
    }

    protected override void Execute(List<GameEntity> entities)
    {
            
            int score = _contexts.game.componentsScore.score;
            _contexts.game.ReplaceComponentsScore(score+entities.Count);
            
    }
    
    public void Initialize()
    {
        Debug.Log("InitializeScore");
        
        _contexts.game.CreateEntity().ReplaceComponentsScore(0);
        Debug.Log(_contexts.game.componentsScore.score);
       // _contexts.game.ReplaceComponentsgoal(0);
    }

}
